<?php
/**
 * Created by PhpStorm.
 * User: fengdh
 * Date: 2019/8/9
 * Time: 17:18
 */

namespace search\controllers\platform;

use business\elasticsearch\services\SupplierRecommendService;
use search\models\SupplierSearchForm;
use yii\web\Controller;

class SupplierController extends Controller
{
    /**
     * 平台供应商搜索
     */
    public function actionIndex()
    {
        $searchForm = new SupplierSearchForm();
        $searchForm->attributes = array_map('common\utils\StringUtils::utf8_clean', $_GET);
        $resultSet = $searchForm->search();

        return $resultSet;
    }

    /**
     * 供应商推荐
     * @return mixed
     */
    public function actionRecommend()
    {
        try {
            $pageIndex = \Yii::$app->request->get('pageIndex', 1);
            $pageSize = \Yii::$app->request->get('pageSize', 10);
            if (!isset($pageIndex)) {
                $pageIndex = 1;
            }
            if (!isset($pageSize)) {
                $pageSize = 10;
            }
            $data = (new SupplierRecommendService())->getList($pageIndex, $pageSize);
            return ['success' => true, 'errorCode' => null, 'message' => null, 'data' => $data];
        } catch (\Exception $ex){
            \Yii::error($ex->getMessage());
            return ['success' => false, 'errorCode' => $ex->getCode(), 'message' => $ex->getMessage(), 'data' => null];
        }
    }
}
